<?php

namespace App\Controllers;

use LowCode\Block;
use LowCode\Page;
use LowCode\UI;

class Auth
{
    public function login()
    {
        if (request()->isPost()){
            $data = [
                "id"=> 1,
                "password"=> '123456',
                "realName"=> 'Admin',
                "roles"=> ['admin'],
                "username"=> 'admin',
                "accessToken"=> uniqid()
            ];
        }else{
            $data = $this->getPage("login");
        }

        return response()->success("ok",$data);
    }

    public function code_login()
    {
        return response()->success("ok",$this->getPage("code-login"));
    }

    public function qrcode_login()
    {
        return response()->success("ok",$this->getPage("qrcode-login"));
    }

    public function forget_password()
    {
        return response()->success("ok",$this->getPage("forget-password"));
    }

    public function register()
    {
        return response()->success("ok",$this->getPage("register"));
    }

    public function getPage($name): Page
    {
        return Page::make(Block::make("LoginController",function (Block $block) use($name) {
            $block->css(".login-module{width:100%;padding:0 50px;margin-top:120px}");
            $block->nodes([
                UI::node($name)->class("login-module")
            ]);
        }));
    }

    public function codes()
    {
        return response()->result([
            "codes"=> ['AC_100100', 'AC_100110', 'AC_100120', 'AC_100010'],
            "username"=> 'admin',
        ]);
    }
}